import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

class Doctor {
    String dCode;
    String dName;
    String dSpec;
    int dHour;
    
    public Doctor() {
        dCode = "";
        dName = "";
        dSpec = "";
        dHour = 0;
    }

    public Doctor(String c, String n, String s, int h) {
        this.dCode = c;
        this.dName = n;
        this.dSpec = s;
        this.dHour = h;
    }
    
    public void setCode(String c) {
        this.dCode = c;
    }
    public void setName(String n) {
        this.dName = n;
    }
    public void setSpec(String s) {
        this.dSpec = s;
    }
    public void setHour(int h) {
        this.dHour = h;
    }
    
    public String getCode() {
        return this.dCode;
    }
    public String getName() {
        return this.dName;
    }
    public String getSpec() {
       return this.dSpec;
    }
    public int getHour() {
        return this.dHour;
    }
    @Override
    public String toString() {
        return "Code: " + dCode
                +"\nName: " + dName
                +"\nSpecialization: " + dSpec
                +"\nHours: " + dHour;
    }
}

class DoctorManager {
    HashMap<String, Doctor> DoctorHashMap = new HashMap<String, Doctor>();
    
    public DoctorManager() {
        
    }
    public void add() {
        Doctor objD = new Doctor();
        Scanner input = new Scanner(System.in);
        System.out.print("Code: ");
        objD.setCode(input.next());
        System.out.print("Name: ");
        objD.setName(input.next());
        System.out.print("Specialization: ");
        objD.setSpec(input.next());
        while(true) {
            try {
                System.out.print("Hours: ");
                objD.setHour(input.nextInt());
                break;
            } catch(Exception ex) {
                System.out.println("Must be a digit.....");
            }
        }
        DoctorHashMap.put(objD.getCode(), objD);
    }
    
    public void search() {
        Scanner input = new Scanner(System.in);
        System.out.print("Input code of Doctor to search: ");
        Doctor objD = DoctorHashMap.get(input.next());
        if(objD != null ) {
            System.out.println(objD.toString());
        } else {
            System.out.println("Code not found....");
        }
    }
    
    public void display() {
        System.out.println("The list has total: " + DoctorHashMap.size() + " doctor");
        Set s = DoctorHashMap.keySet();
        Iterator i = s.iterator();
        while(i.hasNext()) {
            
            System.out.println(DoctorHashMap.get(i.next()).toString());
        }
    }
    
    public static void main(String[] args) {
        int choose = 0;
        Scanner sc = new Scanner(System.in);
        DoctorManager objDoctor = new DoctorManager();
        
        while(true) {
            System.out.println("\n\nLIFELINE HOSPITAL");
            System.out.println("1. Register a doctor ");
            System.out.println("2. Search and Display a doctor");
            System.out.println("3. Publish the entire list");
            System.out.println("4. Exit");
            
            while(true) {
                try {
                    System.out.print("Enter your choose: ");
                    choose = sc.nextInt();
                    break;
                } catch(Exception ex) {
                    System.out.println("Must be a digit.....");
                }
            }
            
            switch (choose) {
                case 1:
                    objDoctor.add();
                    break;
                case 2:
                    objDoctor.search();
                    break;
                case 3:
                    objDoctor.display();
                    break;
                case 4:
                    System.out.println("See you again!");
                    System.exit(0);
                default:
                    System.out.println("Wrong choosen, choose again....");
                    break;
            }
        }
    }
}